﻿Module pscConsole

    Sub Main()
        If My.Application.CommandLineArgs.Contains("/auto") Then
            PowerShellCron.Service.pscBrain.theBrain.ServiceStart()
            Console.WriteLine("SERVICE STARTED")
            While True
                Threading.Thread.Sleep(100)
            End While
            Exit Sub
        Else
        End If

        Console.WindowWidth = Math.Min(120, Console.LargestWindowWidth)
        Console.WriteLine("PowerShellCron Console App (for testing) has started.")
        Console.WriteLine()

        Dim comp As PowerShellCron.Service.pscBrain = PowerShellCron.Service.pscBrain.theBrain

        While True
            'Console.WriteLine("Press [S] to Start Service; [E] to Stop Service; [R] to Reset Database; [T] to run Test; [L] to run Listener; [G] to GC; [Q] to Quit...")
            Console.WriteLine("Press [S] to Start Service; [E] to Stop Service; [T] to run Test; [L] to run Listener; [G] to GC; [Q] to Quit...")
            Dim theKey As String = Console.In.ReadLine().Substring(0, 1)
            Select Case theKey.ToUpper()
                Case "S"
                    Console.Write("Starting Service...")
                    comp.ServiceStart()
                    Console.WriteLine("Started!")

                Case "E"
                    Console.Write("Stopping Service...")
                    comp.ServiceStop()
                    Console.WriteLine("Stopped!")

                    'Case "R"
                    '    If comp.IsServiceRunning Then
                    '        Console.WriteLine("Stopping Service...")
                    '        comp.ServiceStop()
                    '        Console.WriteLine("Stopped!")
                    '    End If
                    '    Console.WriteLine("Resetting Database...")
                    '    comp.ResetDatabase()
                    '    Console.WriteLine("Database is reset!")

                Case "T"
                    comp.CalcNextTime()

                Case "L"
                    comp.RunListener()
                Case "Q"
                    If comp.IsServiceRunning Then
                        comp.ServiceStop()
                    End If
                    Console.WriteLine("Quitting...")
                    Exit While
                Case "G"
                    GC.Collect()
            End Select
        End While
        Console.WriteLine("PowerShellCron Console App (for testing) has quit.")
    End Sub
End Module

